<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="wrap">
        <h2>哈哈哈哈</h2>
        <ul class="list one" title="">
            <li id="first">01</li>
            <li class="second">02</li>
            <li>03</li>
            <li name="last">04</li>
        </ul>
        <ul class="list two" title="">
            <li id="first">01</li>
            <li class="second">02</li>
            <li>03</li>
            <li name="last">04</li>
        </ul>
    </div>
</body>
<script>
    //  document.getElementsByClassName()  获取相同class属性的节点列表  IE8及以下不支持
    // 封装一个方法 从页面的所有元素中 找到含有指定class名的元素 放到数组中 => 返回

    function Get(className) {
        var list = document.getElementsByTagName("*");
        var classArr = [];
        for (var i = 0; i < list.length; i++) {
            var ele = list[i];
            var _class = ele.getAttribute("class")
            if (_class) { //有值 => 含有class名
                var classlist = _class.split(" ");//将class以空格分成新数组
                console.log(classlist);
                if(indexOf(classlist , className) != -1){
                    classArr.push(ele);
                }
            }
        }
        return classArr;
    }

    Get("second");
    console.log(Get("second"));
</script>

</html>